package com.cdzx.quartz.service;

import com.cdzx.quartz.job.HelloJob;
import org.quartz.*;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

@Service
public class ScheduleJobServiceImpl {
    @Resource
    private Scheduler scheduler;
    public void addJob() throws Exception {
        JobDetail jobDetail = JobBuilder.newJob(HelloJob.class).withIdentity("hello","hello").build();
        jobDetail.getJobDataMap().put("name","3232");
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("0/5 * * * * ?").withMisfireHandlingInstructionDoNothing();
        CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity("hello","hello").withSchedule(scheduleBuilder).build();
        scheduler.scheduleJob(jobDetail, trigger);
    }
}
